Passed
Push — master ( 5f67fe...8bce0b )
by Jesús
02:16
created

themeLogic.ts ➔ getOppositeThemeName   A

Complexity

Conditions 2

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
export type Theme = 'light' | 'dark';
2
3
export const DEFAULT_THEME: Theme = 'dark';
4
5
export function toggleTheme(current: string | null): Theme {
6
  return current === 'dark' ? 'light' : 'dark';
7
}
8
9
export function isValidTheme(theme: string): theme is Theme {
10
  return theme === 'light' || theme === 'dark';
11
}
12
13
export function getThemeOrDefault(theme: string | null): Theme {
14
  if (theme && isValidTheme(theme)) {
15
    return theme;
16
  }
17
  return DEFAULT_THEME;
18
}
19
20
export function isDarkMode(theme: string): boolean {
21
  return theme === 'dark';
22
}
23
24
export function getOppositeThemeName(theme: string): string {
25
  return theme === 'dark' ? 'light' : 'dark';
26
}
27
28
export function getAriaPressed(theme: string): 'true' | 'false' {
29
  return isDarkMode(theme) ? 'true' : 'false';
30
}
31
32
export function getThemeToggleLabel(currentTheme: string): string {
33
  const opposite = getOppositeThemeName(currentTheme);
34
  return `Switch to ${opposite} mode`;
35
}
36